<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends BaseController {
	/*
	 * 首页 图片和文字
	 */
    public function index(){
	    session_start();
	    $options = C('WECHAT_OPTIONS');
	    $wechatObj = new \Org\WechatTest\WechatTest($options);

	    //是否在微信内
	    $inwechat = $wechatObj->inwechat();

	    //微信授权
	    $siteurl = C('SITEURL');
	    $redirect_url = $_SERVER['REQUEST_URI'];
	    if($inwechat & $_SESSION['wxuserid'] <= 0){
		    $wechatObj->wxauth('HOME',$redirect_url,$siteurl);
	    }

		$this->display('testbao');
	}

	/*
	 * js测试
	 */
	public function testjs(){
		//签名信息
		$options = C('WECHAT_OPTIONS');
		$wechatObj = new \Org\WechatTest\WechatTest($options);
		$signinfo = $wechatObj->getSignPackage();

		//链接信息
		$linkinfo = array(
			'title'   => '首页',
			'desc'    => '欣欣的公众号',
			'link'    => 'http://xinxin.oschina.mopaas.com/index.php',
			'imgUrl'  => 'http://mmbiz.qpic.cn/mmbiz/9vhD5XbU5uiaYOpOYOOEib1Tl6we6ZRoibcC0icibicaqic7SZ41QyjI0HO4B2Wp67steNNws5OLCpY39dhoJaFYJN29A/0?wx_fmt=jpeg',
		);

		//网站名
		$siteurl = C('SITEURL');

		$this->assign('signinfo',$signinfo);
		$this->assign('linkinfo',$linkinfo);
		$this->assign('siteurl',$siteurl);
		$this->display();
	}

	/*
	 * 添加页面
	 */
	public function add(){
		$model = M('order');
		$oname = I('oname');

		$addData = array(
			'goodname' => $oname,
		);

		$model->add($addData);
		$this->redirect('index');

	}

	/*
	 * 测试图片页面
	 */
	public function testpics(){
		$this->display();
	}

	/*
	 * 加载图片
	 */
	public function loadpic(){
		$arr = array();
		$handle = opendir('./Public/mypic');
		while($file = readdir($handle)){
			if($file == '.' || $file == '..'){
				continue;
			}
			$arr[] = $file;
		}
		echo json_encode($arr);
	}

	/*
	 * 微信测试
	 */
	public function wxtest(){
		$media = array(
	 		'media' => '@C:\Users\Administrator\Desktop\12.jpg'
		);
		$options = C('WECHAT_OPTIONS');
		$wechatObj = new \Org\WechatTest\WechatTest($options);
		$info = $wechatObj->getmedia();
//		$info = $wechatObj->mediaupload($media);
		var_dump($info);exit;

	}

	/*
	 * bootstrap测试
	 */
	public function bootstrap(){
		$this->display();
	}


}